      SUBROUTINE CATEG ( STRING, TYPE, FORM )
C*
C*                  *******************************
C*                  *******************************
C*                  **                           **
C*                  **          CATEG            **
C*                  **                           **
C*                  *******************************
C*                  *******************************
C*
C*     SUBPROGRAM :
C*          FIND THE TYPE OF A STRING
C*
C*     AUTHOR :
C*          ART RAGOSTA
C*          MS 207-5
C*          AMES RESEARCH CENTER
C*          MOFFETT FIELD, CA   94035
C*          (415) 694-5578
C*
C*     PURPOSE :
C*          TO CATEGORIZE A STRING AS EITHER A LOGICAL, INTEGER, FLOATING,
C*          E-FLOATING, D-FLOATING, OR ALPHANUMERIC.
C*          ALTHOUGH QUITE ACCURATE, IT IS NOT FOOL-PROOF.
C*
C*     INPUT ARGUMENTS :
C*          STRING - THE STRING CONTAINING THE STRING TO CHECK
C*
C*     OUTPUT ARGUMENTS :
C*          TYPE   - 'L', 'I', 'F', 'E', 'D', 'A'
C*          FORM   - A VALID FORTRAN FORMAT FIELD FOR THIS STRING
C*
C*     INTERNAL WORK AREAS :
C*          NONE
C*
C*     COMMON BLOCKS :
C*          NONE
C*
C*     FILE REFERENCES :
C*          NONE
C*
C*     DATA BASE ACCESS :
C*          NONE
C*
C*     SUBPROGRAM REFERENCES :
C*          BLANKS,  CAPS
C*
C*     ERROR PROCESSING :
C*          NONE
C*
C*     TRANSPORTABILITY LIMITATIONS :
C*          NON-STANDARD VARIABLE FIELD FORMAT STATEMENTS
C*
C*     ASSUMPTIONS AND RESTRICTIONS :
C*          NONE
C*
C*     LANGUAGE AND COMPILER :
C*          ANSI FORTRAN 77
C*
C*     VERSION AND DATE :
C*          VERSION I.0      8-FEB-85
C*
C*     CHANGE HISTORY :
C*           8-FEB-85    INITIAL VERSION
C*
C***********************************************************************
C*
      CHARACTER *(*) STRING, FORM
      CHARACTER *1 TYPE, LET
C
      CALL BLANKS ( STRING, L )
      CALL CAPS ( STRING )
C
C --- DEFAULT TYPE IS ALPHANUMERIC, DEFAULT FORMAT IS 'Ann'
C
      TYPE = 'A'
      LF   = LEN ( STRING )
      IFM  = 1
      IF (LF .GT. 9) IFM = 2
      IF (LF .GT. 99) IFM = 3
      WRITE ( FORM, 900 ) LF
      IS   = 1
      MC   = 0
C
C --- CHECK FOR LOGICAL TYPE
C
      IF (STRING(IS:IS) .EQ. '.') THEN
         IF ((STRING(IS:IS+2) .EQ. '.T.') .OR.
     $       (STRING(IS:IS+2) .EQ. '.F.')) THEN
            IF (L .EQ. 3) THEN
               TYPE = 'L'
               FORM = 'L3'
            ENDIF
            RETURN
         ENDIF
         IF (STRING(IS:IS+5) .EQ. '.TRUE.') THEN
            IF (L .EQ. 6) THEN
               TYPE = 'L'
               FORM = 'L6'
            ENDIF
            RETURN
         ENDIF
         IF (STRING(IS:IS+6) .EQ. '.FALSE.') THEN
            IF (L .EQ. 7) THEN
               TYPE = 'L'
               FORM = 'L7'
            ENDIF
            RETURN
         ENDIF
      ENDIF
C
C --- CHECK FOR NUMERIC
C
      IF ((STRING(IS:IS) .EQ. '+') .OR. (STRING(IS:IS) .EQ. '-'))
     $  IS = IS + 1
C
C --- SIGN AND DIGITS ONLY... ITS AN INTEGER
C
10    IF (IS .GT. L) THEN
         TYPE = 'I'
         IS   = IS - 1
         IFM  = 1
         IF (IS .GT. 9) IFM = 2
         WRITE (FORM, 910) IS
         RETURN
      ENDIF
      IF ((STRING(IS:IS) .LT. '0') .OR. (STRING(IS:IS) .GT. '9'))GOTO 20
      IS = IS + 1
      GO TO 10
C
C --- IN ORDER TO BE A NUMBER THE NEXT CHARACTER MUST BE '.', 'E', 'D'
C
20    IF (STRING(IS:IS) .NE. '.') THEN
         IF ((STRING(IS:IS) .EQ. 'E') .OR. (STRING(IS:IS) .EQ. 'D'))
     $    GO TO 40
         RETURN
      ENDIF
      IS = IS + 1
C
C --- 'INTEGER' '.' 'INTEGER' ONLY... IT'S FIXED POINT
C
30    IF (IS .GT. L) THEN
         TYPE = 'F'
         IS   = IS - 1
         IFM  = 1
         IF (IS .GT. 9) IFM = 2
         IFM1 = 1
         IF (MC .GT. 9) IFM1 = 2
         WRITE (FORM, 920) IS, MC
         RETURN
      ENDIF
      IF ((STRING(IS:IS) .LT. '0') .OR. (STRING(IS:IS) .GT. '9'))GOTO 40
      MC = MC + 1
      IS = IS + 1
      GO TO 30
C
C --- THE NEXT CHARACTER MUST BE AN EXPONENT TO BE FLOATING
C
40    IF (STRING(IS:IS) .EQ. 'E') THEN
         LET = 'E'
      ELSE IF(STRING(IS:IS) .EQ. 'D') THEN
         LET = 'D'
      ELSE
         RETURN
      ENDIF
      IS = IS + 1
      IF ((STRING(IS:IS) .EQ. '-') .OR. (STRING(IS:IS) .EQ. '+'))
     $  IS = IS + 1
C
C --- IF THE REST IS AN EXPONENT, ITS FLOATING POINT
C
50    IF (IS .GT. L) THEN
         IS = IS - 1
         IFM = 1
         IF (IS .GT. 9) IFM = 2
         IFM1 = 1
         IF (MC .GT. 9) IFM1 = 2
         WRITE (FORM,930) LET,IS,MC
         TYPE = LET
         RETURN
      ENDIF
      IF ((STRING(IS:IS) .GE. '0') .AND. (STRING(IS:IS) .LE. '9')) THEN
         IS = IS + 1
         GO TO 50
      ENDIF
      RETURN
900   FORMAT ( 'A',I<IFM> )
910   FORMAT ( 'I',I<IFM> )
920   FORMAT ( 'F',I<IFM>,'.',I<IFM1> )
930   FORMAT ( A1,I<IFM>,'.',I<IFM1> )
      END
C
C---END CATEG
C
